Skip to content

fix(v10/nextjs): Remove tracing from middleware wrappers - #22904

Merged
chargome merged 2 commits into
v10from
backport/v10-nextjs-no-double-middleware-span
Jul 31, 2026
Merged

fix(v10/nextjs): Remove tracing from middleware wrappers#22904
chargome merged 2 commits into
v10from
backport/v10-nextjs-no-double-middleware-span

Conversation

@chargome

@chargome chargome commented Jul 31, 2026

Copy link
Copy Markdown
Member

Backport of: #18456

Fixes #22636

@chargome chargome self-assigned this Jul 31, 2026
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.75 kB added added
@sentry/browser - with treeshaking flags 26.19 kB added added
@sentry/browser (incl. Tracing) 46.6 kB added added
@sentry/browser (incl. Tracing + Span Streaming) 48.38 kB added added
@sentry/browser (incl. Tracing, Profiling) 51.34 kB added added
@sentry/browser (incl. Tracing, Replay) 85.84 kB added added
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.48 kB added added
@sentry/browser (incl. Tracing, Replay with Canvas) 90.55 kB added added
@sentry/browser (incl. Tracing, Replay, Feedback) 103.2 kB added added
@sentry/browser (incl. Feedback) 44.92 kB added added
@sentry/browser (incl. sendFeedback) 32.55 kB added added
@sentry/browser (incl. FeedbackAsync) 37.68 kB added added
@sentry/browser (incl. Metrics) 28.84 kB added added
@sentry/browser (incl. Logs) 29.07 kB added added
@sentry/browser (incl. Metrics & Logs) 29.76 kB added added
@sentry/react 29.55 kB added added
@sentry/react (incl. Tracing) 48.86 kB added added
@sentry/vue 33.17 kB added added
@sentry/vue (incl. Tracing) 48.56 kB added added
@sentry/svelte 27.78 kB added added
CDN Bundle 30.14 kB added added
CDN Bundle (incl. Tracing) 48.56 kB added added
CDN Bundle (incl. Logs, Metrics) 31.73 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) 49.86 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) 70.99 kB added added
CDN Bundle (incl. Tracing, Replay) 86.05 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.36 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) 91.86 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 93.12 kB added added
CDN Bundle - uncompressed 89.9 kB added added
CDN Bundle (incl. Tracing) - uncompressed 146.78 kB added added
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.61 kB added added
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.75 kB added added
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.37 kB added added
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.01 kB added added
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.98 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.71 kB added added
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.67 kB added added
@sentry/nextjs (client) 51.4 kB added added
@sentry/sveltekit (client) 47.02 kB added added
@sentry/core/server 80.44 kB added added
@sentry/core/browser 66.78 kB added added
@sentry/node-core 63.25 kB added added
@sentry/node 125.89 kB added added
@sentry/node (incl. diagnostics channel injection) 151.33 kB added added
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB added added
@sentry/node/light 51.41 kB added added
@sentry/node - without tracing 74.94 kB added added
@sentry/aws-serverless 84.21 kB added added
@sentry/cloudflare (withSentry) - minified 200.5 kB added added
@sentry/cloudflare (withSentry) 492.68 kB added added

Next.js only emits the native `Middleware.execute` OTel span from v14 onwards, so
relying on it unconditionally dropped middleware transactions entirely on Next.js 13,
which v10 still supports. Fall back to starting the wrapper span when no root span is
active.
@chargome
chargome marked this pull request as ready for review July 31, 2026 14:15
@chargome
chargome requested a review from a team as a code owner July 31, 2026 14:15
@chargome
chargome requested review from a team, logaretm, nicohrubec and s1gr1d and removed request for a team July 31, 2026 14:15
@chargome

Copy link
Copy Markdown
Member Author

@logaretm this just conditionally adds the tracing for v13

@chargome
chargome merged commit 57f509f into v10 Jul 31, 2026
79 checks passed
@chargome
chargome deleted the backport/v10-nextjs-no-double-middleware-span branch July 31, 2026 14:20
sergical added a commit to getsentry/sentry-docs that referenced this pull request Jul 31, 2026
…#18887)

## DESCRIBE YOUR PR

#18775 dropped middleware root spans entirely; this restores them at a
blind 1% (~24k/day), blind because Next.js creates the
`Middleware.execute` root in a detached sandbox before any request data
reaches Sentry, so `tracesSampler` can never classify it.
`middleware.ts` tags that span with `middleware.outcome`
(redirect/rewrite/passthrough), `url.path`, `traffic_type`, and
`device_type` — attributes rather than a span name, because the SDK's
`enhanceMiddlewareRootSpan` unconditionally rewrites
`Middleware.execute` names to `middleware {METHOD}` on the send path and
ignores `sentry.source`. `isMiddlewareRootSpan` now matches both
`http.server.middleware` (SDK v10) and `middleware` (v11) so detection
survives the upgrade.

Note that v10 still emits a duplicate nested middleware span, so volume
may be ~2x until getsentry/sentry-javascript#22904 lands — unrelated to
this rate, and a non-zero rate is what makes that fix observable here at
all. To verify after deploy: `spans · span.op:http.server.middleware ·
release:<new sha>` is non-zero at ~1% of request volume with
`middleware.outcome` populated, and `docs.request.classified` grouped by
`traffic_type` is unchanged.

## IS YOUR CHANGE URGENT?

Help us prioritize incoming PRs by letting us know when the change needs
to go live.
- [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE -->
- [ ] Other deadline: <!-- ENTER DATE HERE -->
- [x] None: Not urgent, can wait up to 1 week+

## SLA

- Teamwork makes the dream work, so please add a reviewer to your PRs.
- Please give the docs team up to 1 week to review your PR unless you've
added an urgent due date to it.
Thanks in advance for your help!

## PRE-MERGE CHECKLIST

*Make sure you've checked the following before merging your changes:*

- [ ] Checked Vercel preview for correctness, including links
- [ ] PR was reviewed and approved by any necessary SMEs (subject matter
experts)
- [ ] PR was reviewed and approved by a member of the [Sentry docs
team](https://github.com/orgs/getsentry/teams/docs)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants